-
Notifications
You must be signed in to change notification settings - Fork 14k
num: Implement uint_gather_scatter_bits feature for unsigned integers
#149097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Implement `gather_bits`, `scatter_bits` functions on unsigned integers Add tests to coretests
|
rustbot has assigned @Mark-Simulacrum. Use |
| fn test_gather_bits() { | ||
| assert_eq_const_safe!($T: A.gather_bits(B), 0b_0010); | ||
| assert_eq_const_safe!($T: A.gather_bits(C), 0b_1010); | ||
|
|
||
| assert_eq_const_safe!($T: B.gather_bits(A), 0b_0100); | ||
| assert_eq_const_safe!($T: B.gather_bits(C), 0b_1001); | ||
|
|
||
| assert_eq_const_safe!($T: C.gather_bits(A), 0b_0110); | ||
| assert_eq_const_safe!($T: C.gather_bits(B), 0b_0011); | ||
|
|
||
| assert_eq_const_safe!($T: A.gather_bits(_0), 0); | ||
| assert_eq_const_safe!($T: B.gather_bits(_0), 0); | ||
| assert_eq_const_safe!($T: C.gather_bits(_0), 0); | ||
| assert_eq_const_safe!($T: _0.gather_bits(A), 0); | ||
| assert_eq_const_safe!($T: _0.gather_bits(B), 0); | ||
| assert_eq_const_safe!($T: _0.gather_bits(C), 0); | ||
|
|
||
| assert_eq_const_safe!($T: A.gather_bits(_1), A); | ||
| assert_eq_const_safe!($T: B.gather_bits(_1), B); | ||
| assert_eq_const_safe!($T: C.gather_bits(_1), C); | ||
| assert_eq_const_safe!($T: _1.gather_bits(A), 0b0000_0111); | ||
| assert_eq_const_safe!($T: _1.gather_bits(B), 0b0000_0011); | ||
| assert_eq_const_safe!($T: _1.gather_bits(C), 0b0001_1111); | ||
| } | ||
|
|
||
| fn test_scatter_bits() { | ||
| assert_eq_const_safe!($T: A.scatter_bits(B), 0); | ||
| assert_eq_const_safe!($T: A.scatter_bits(C), 0b0011_0000); | ||
|
|
||
| assert_eq_const_safe!($T: B.scatter_bits(A), 0b0000_0100); | ||
| assert_eq_const_safe!($T: B.scatter_bits(C), 0b0000_0001); | ||
|
|
||
| assert_eq_const_safe!($T: C.scatter_bits(A), 0b_0000_0100); | ||
| assert_eq_const_safe!($T: C.scatter_bits(B), 0b_0000_0001); | ||
|
|
||
| assert_eq_const_safe!($T: A.scatter_bits(_0), 0); | ||
| assert_eq_const_safe!($T: B.scatter_bits(_0), 0); | ||
| assert_eq_const_safe!($T: C.scatter_bits(_0), 0); | ||
| assert_eq_const_safe!($T: _0.scatter_bits(A), 0); | ||
| assert_eq_const_safe!($T: _0.scatter_bits(B), 0); | ||
| assert_eq_const_safe!($T: _0.scatter_bits(C), 0); | ||
|
|
||
| assert_eq_const_safe!($T: A.scatter_bits(_1), A); | ||
| assert_eq_const_safe!($T: B.scatter_bits(_1), B); | ||
| assert_eq_const_safe!($T: C.scatter_bits(_1), C); | ||
| assert_eq_const_safe!($T: _1.scatter_bits(A), A); | ||
| assert_eq_const_safe!($T: _1.scatter_bits(B), B); | ||
| assert_eq_const_safe!($T: _1.scatter_bits(C), C); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These tests are difficult to manually review without seeing the constants, so I've duplicated the values and used the x86 intrinsics to show the tests produce the same values.
Feature gate:
#![feature(uint_gather_scatter_bits)]Tracking issue: #149069
Accepted ACP: rust-lang/libs-team#695 (comment)
Implement
gather_bits,scatter_bitsfunctions on unsigned integersAdd tests to coretests
This implementation is a small improvement over the plain naive form (see the solution sketch).
We only check the set bits in the mask instead of iterating over every bit.